﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace StairsModuleAndEdit.StairsModel.CommonUnit
{
	public class ValueValidatingKit
	{
		public static bool ValidatingInt(string strValue, int min, int max, ref int nValue)
		{
			int num = 0;
			try
			{
				num = Convert.ToInt32(strValue);
			}
			catch (Exception)
			{
				return false;
			}
			if (num > min && num < max)
			{
				nValue = num;
				return true;
			}
			return false;
		}

		public static bool ValidatingInt(string strValue, ValidatingType validatingType, ref int nValue)
		{
			int num = 0;
			try
			{
				num = Convert.ToInt32(strValue);
			}
			catch (Exception)
			{
				return false;
			}
			if (validatingType == ValidatingType.GreaterThanZero && num > 0)
			{
				nValue = num;
				return true;
			}
			if (validatingType == ValidatingType.GreaterThanAndEqualZero && num >= 0)
			{
				nValue = num;
				return true;
			}
			if (validatingType == ValidatingType.ZeroTo2PI && num >= 0 && num < 360)
			{
				nValue = num;
				return true;
			}
			if (validatingType == ValidatingType.Minus2PITo2PI && num > -360 && num < 360)
			{
				nValue = num;
				return true;
			}
			if (validatingType == ValidatingType.None)
			{
				nValue = num;
				return true;
			}
			return false;
		}

		public static bool ValidatingDouble(string strValue, double min, double max, ref double nValue)
		{
			double num = 0.0;
			try
			{
				num = Convert.ToDouble(strValue);
			}
			catch (Exception)
			{
				return false;
			}
			if (Geometry.Greaterthan_Or_Equal(num, min) && Geometry.Lessthan_Or_Equal(num, max))
			{
				nValue = num;
				return true;
			}
			return false;
		}

		public static bool ValidatingDouble(string strValue, ValidatingType validatingType, ref double dValue)
		{
			double num = 0.0;
			try
			{
				num = Convert.ToDouble(strValue);
			}
			catch (Exception)
			{
				return false;
			}
			if (validatingType == ValidatingType.GreaterThanZero && Geometry.GreaterThan(num, 0.0))
			{
				dValue = num;
				return true;
			}
			if (validatingType == ValidatingType.GreaterThanAndEqualZero && Geometry.Greaterthan_Or_Equal(num, 0.0))
			{
				dValue = num;
				return true;
			}
			if (validatingType == ValidatingType.Minus2PITo2PI && Geometry.GreaterThan(num, -360.0) && Geometry.LessThan(num, 360.0))
			{
				dValue = num;
				return true;
			}
			if (validatingType == ValidatingType.ZeroTo2PI && Geometry.Greaterthan_Or_Equal(num, 0.0) && Geometry.LessThan(num, 360.0))
			{
				dValue = num;
				return true;
			}
			if (ValidatingType.GreaterThan == validatingType && Geometry.GreaterThan(num, dValue))
			{
				dValue = num;
				return true;
			}
			if (validatingType == ValidatingType.None)
			{
				dValue = num;
				return true;
			}
			return false;
		}

		public static bool IsInvalidLandingWidthRange(double dValue)
		{
			bool result = false;
			if (dValue > 5000000.0)
			{
				result = true;
			}
			return result;
		}

		public static bool IsInvalidControlTextValue(List<System.Windows.Forms.Control> arCtrls, ref Control refTextBox)
		{
			bool result = false;
			foreach (System.Windows.Forms.Control control in arCtrls)
			{
				string text = control.Text;
				if (string.IsNullOrEmpty(text) || text.StartsWith("."))
				{
					refTextBox = control;
					result = true;
					break;
				}
			}
			return result;
		}
	}
}
